import { PayloadMcuid, PayloadUser, Public } from '@libs/common/decorator';
import { IndexInterceptor } from '@libs/common/interceptors';
import { Body, Controller, Post, UseInterceptors } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { DeviceCargoLaneService } from './device-cargo-lane.service';
import {
  FindDeviceCargoLaneDto,
  IndexDeviceCargoLaneDto,
  OfflineDeviceCargoLaneDto,
  ReplenishDeviceCargoLaneDto,
  ShowDeviceCargoLaneDto,
  StoreDeviceCargoLaneDto,
  UpdateDeviceCargoLaneDto,
} from './dto/device-cargo-lane.dto';

@ApiTags('ATM货道管理')
@Controller('atm/device-cargo-lane')
export class DeviceCargoLaneController {
  constructor(
    private readonly deviceCargoLaneService: DeviceCargoLaneService,
  ) {}

  @Post('index')
  @UseInterceptors(new IndexInterceptor())
  index(
    @Body() dto: IndexDeviceCargoLaneDto,
    @PayloadUser() user: SC.User.SysInfo,
    @PayloadMcuid() mcuid: string,
  ) {
    return this.deviceCargoLaneService.index(dto, user, mcuid);
  }

  @Post('show')
  show(@Body() dto: ShowDeviceCargoLaneDto, @PayloadMcuid() mcuid: string) {
    return this.deviceCargoLaneService.show(dto, mcuid);
  }

  @Post('init')
  init(@PayloadMcuid() mcuid: string) {
    return this.deviceCargoLaneService.init(mcuid);
  }

  @Post('update')
  update(@Body() dto: UpdateDeviceCargoLaneDto, @PayloadMcuid() mcuid: string) {
    return this.deviceCargoLaneService.update(mcuid, dto);
  }

  @Post('find')
  async find(
    @Body() dto: FindDeviceCargoLaneDto,
    @PayloadMcuid() mcuid: string,
  ) {
    return this.deviceCargoLaneService.find(mcuid, dto);
  }

  // 补货
  @Post('replenish')
  replenish(
    @Body() dto: ReplenishDeviceCargoLaneDto,
    @PayloadUser() user: SC.User.SysInfo,
    @PayloadMcuid() mcuid: string,
  ) {
    return this.deviceCargoLaneService.replenish(dto, user, mcuid);
  }

  @Post('mobile/find')
  @Public()
  mobileFind(@PayloadMcuid() mcuid: string) {
    return this.deviceCargoLaneService.mobileFind(mcuid);
  }

  // 商品货道库存
  @Post('store')
  @Public()
  store(@Body() dto: StoreDeviceCargoLaneDto, @PayloadMcuid() mcuid: string) {
    return this.deviceCargoLaneService.store(dto, mcuid);
  }

  // 下架商品
  @Post('offline')
  offline(
    @Body() dto: OfflineDeviceCargoLaneDto,
    @PayloadMcuid() mcuid: string,
  ) {
    return this.deviceCargoLaneService.offline(dto, mcuid);
  }
}
